package com.linksfield.topup.controller.planmanage;

import com.alibaba.fastjson.JSON;
import com.linksfield.topup.config.dto.ResultDataDto;
import com.linksfield.topup.config.dto.StringOutputConstant;
import com.linksfield.topup.entity.interfaces.planmanage.createserviceplan.request.RequestCreateServicePlan;
import com.linksfield.topup.entity.interfaces.planmanage.edit.request.RequestServicePlanEdit;
import com.linksfield.topup.entity.interfaces.planmanage.edit.response.ResponseEdit;
import com.linksfield.topup.entity.interfaces.planmanage.editpageoperate.request.RequestEditPageOperate;
import com.linksfield.topup.entity.interfaces.planmanage.languge.request.RequestPartnerLanguageType;
import com.linksfield.topup.entity.interfaces.planmanage.languge.response.ResponsePartnerLanguageType;
import com.linksfield.topup.entity.interfaces.planmanage.operate.request.RequestServicePlanOperate;
import com.linksfield.topup.entity.interfaces.planmanage.packagebasicinfo.request.RequestPackageBasicInfo;
import com.linksfield.topup.entity.interfaces.planmanage.packagebasicinfo.response.ResponsePackageBasicInfo;
import com.linksfield.topup.entity.interfaces.planmanage.packagelist.request.RequestPackageNameList;
import com.linksfield.topup.entity.interfaces.planmanage.packagelist.response.ResponsePackageNameList;
import com.linksfield.topup.entity.interfaces.planmanage.partnernamelist.request.RequestPartnerNameList;
import com.linksfield.topup.entity.interfaces.planmanage.partnernamelist.response.ResponsePartnerNameList;
import com.linksfield.topup.entity.interfaces.planmanage.search.request.RequestServicePlanSearch;
import com.linksfield.topup.entity.interfaces.planmanage.search.response.ResponseSearch;
import com.linksfield.topup.service.ServicePlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 套餐管理控制器类
 *
 * @author: lm
 * @date: 2019-11-26 15:30
 */
@RestController
@Api(value = "套餐管理")

public class ServicePlanManageController {

    @Autowired
    ServicePlanService planService;

    private static Logger logger = Logger.getLogger(ServicePlanManageController.class);


    @PostMapping(value = "partnerLanguageType", produces = "application/json;charset=utf-8")
    @ApiOperation(value = "获取企业配置：语言类型", response = ResponsePartnerLanguageType.class)
    public ResultDataDto partnerLanguageType(@ApiParam @RequestBody RequestPartnerLanguageType request,
                                             @RequestHeader(name = "x-access-token", required = false) String token) {
        logger.info("【获取企业配置：语言类型】请求：" + JSON.toJSONString(request));
        if (StringUtils.isBlank(token)) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_TOKEN_EMPTY);
        }
        return planService.partnerLanguageType(request, token);
    }

    @PostMapping(value = "partnerList", produces = "application/json;charset=utf-8")
    @ApiOperation(value = "下拉可新建套餐的企业列表", response = ResponsePartnerNameList.class)
    public ResultDataDto partnerList(@ApiParam @RequestBody RequestPartnerNameList request,
                                     @RequestHeader(name = "x-access-token", required = false) String token) {
        logger.info("【下拉：可新建套餐的企业列表】请求：" + JSON.toJSONString(request));
        if (StringUtils.isBlank(token)) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_TOKEN_EMPTY);
        }
        return planService.partnerList(request, token);

    }


    @PostMapping(value = "packageNameList", produces = "application/json;charset=utf-8")
    @ApiOperation(value = "获取原始套餐名称列表:下拉组别", response = ResponsePackageNameList.class)
    public ResultDataDto packageNameList(@ApiParam @RequestBody RequestPackageNameList request,
                                         @RequestHeader(name = "x-access-token", required = false) String token) {
        logger.info("【获取原始套餐名称列表:下拉组别】请求：" + JSON.toJSONString(request));
        if (StringUtils.isBlank(token)) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_TOKEN_EMPTY);
        }
        return planService.packageNameList(request, token);

    }


    @PostMapping(value = "packageBasicInfo", produces = "application/json;charset=utf-8")
    @ApiOperation(value = "原始套餐基本信息:新建页面右侧基本信息", response = ResponsePackageBasicInfo.class)
    public ResultDataDto packageBasicInfo(@ApiParam @RequestBody RequestPackageBasicInfo request,
                                          @RequestHeader(name = "x-access-token", required = false) String token) {
        logger.info("【原始套餐基本信息:新建页面右侧基本信息】请求：" + JSON.toJSONString(request));
        if (StringUtils.isBlank(token)) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_TOKEN_EMPTY);
        }
        return planService.packageBasicInfo(request, token);
    }


    @PostMapping(value = "createServicePlan", produces = "application/json;charset=utf-8")
    @ApiOperation(value = "新建：可售卖的套餐服务计划")
    public ResultDataDto createServicePlan(@ApiParam @RequestBody RequestCreateServicePlan request,
                                           @RequestHeader(name = "x-access-token", required = false) String token) {
        logger.info("【新建：可售卖的套餐服务计划】请求：" + JSON.toJSONString(request));
        if (StringUtils.isBlank(token)) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_TOKEN_EMPTY);
        }
        return planService.createServicePlan(request, token);
    }


    @PostMapping(value = "servicePlanSearch", produces = "application/json;charset=utf-8")
    @ApiOperation(value = "套餐管理：搜索", response = ResponseSearch.class)
    public ResultDataDto servicePlanSearch(@ApiParam @RequestBody RequestServicePlanSearch request,
                                           @RequestHeader(name = "x-access-token", required = false) String token) {
        logger.info("【套餐管理搜索】请求：" + JSON.toJSONString(request));
        if (StringUtils.isBlank(token)) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_TOKEN_EMPTY);
        }
        return planService.search(request, token);
    }


    @PostMapping(value = "servicePlanEdit", produces = "application/json;charset=utf-8")
    @ApiOperation(value = "套餐管理：编辑-详情", response = ResponseEdit.class)
    public ResultDataDto servicePlanEdit(@ApiParam @RequestBody RequestServicePlanEdit request,
                                         @RequestHeader(name = "x-access-token", required = false) String token) {
        logger.info("套餐管理【编辑-详情】请求：" + JSON.toJSONString(request));
        if (StringUtils.isBlank(token)) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_TOKEN_EMPTY);
        }
        return planService.edit(request, token);

    }


    @PostMapping(value = "editOperate", produces = "application/json;charset=utf-8")
    @ApiOperation(value = "编辑页面-保存或者上架")
    public ResultDataDto editPageOperate(@ApiParam @RequestBody RequestEditPageOperate request,
                                         @RequestHeader(name = "x-access-token", required = false) String token) {
        logger.info("【编辑页面-保存或者上架】请求：" + JSON.toJSONString(request));
        if (StringUtils.isBlank(token)) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_TOKEN_EMPTY);
        }
        return planService.editPageOperate(request, token);

    }


    @PostMapping(value = "servicePlanOperate", produces = "application/json;charset=utf-8")
    @ApiOperation(value = "套餐管理：操作：全部上架/全部下架/单独上架/单独下架")
    public ResultDataDto servicePlanOperate(@ApiParam @RequestBody RequestServicePlanOperate request,
                                            @RequestHeader(name = "x-access-token", required = false) String token) {
        logger.info("套餐管理【上下架操作】请求：" + JSON.toJSONString(request));
        if (StringUtils.isBlank(token)) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_TOKEN_EMPTY);
        }
        return planService.operate(request, token);

    }


}
